# -*- coding: utf-8 -*-

#    Stingingnettlepy - A static website generator written in Python
#    Copyright (C) 2013  Jannik Haberbosch
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#	Description:
#		This file contains constants for 'Stingingnettlepy'.


# Importion of modules from the Python Standard Library.
import os
import os.path

# Definition of file-contents.
CONTENT_CSS_FILE = \
"""
/* A bit of CSS resetting. */
*
{
	padding:0;
	margin:0;
}
/* CSS for the body tag. */
body
{
	font-family:sans-serif;
	font-size:1.0em;
}
""".strip()

CONTENT_JS_FILE = \
"""
function add_two( a, b )
{
	return a + b;
}
""".strip()

CONTENT_BASIC_TEMPLATE = \
"""
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<title>$website_title</title>
	</head>
	<body>
		<h1>$website_title</h1>
		$main_navigation
		$sub_navigation
		$main_content
		<p>A template is made up of HTML code and placeholders.  Placeholders are some special kind of sequences which will be replaced by another value during the generation of the website.</p>
		<p>A placeholder consists of a dollar sign, and an alphabetic sequence, such as '$important'.  The dollar sign can be escaped by writing two consecutive dollar signs, e.g. '$$'.</p>
	</body>
</html>
""".strip()

CONTENT_ADVANCED_TEMPLATE = \
"""
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<title>$website_title</title>
	</head>
	<body>
		<h1>$website_title</h1>
		$main_navigation
		$sub_navigation		
		$main_content
		$container_two
	</body>
</html>
""".strip()

CONTENT_GLOBAL_CONFIG_FILE = \
"""
{
	"template": "basic.template",
	"website_title": "The title of the website"
}
""".strip()

CONTENT_IN_HOME_LOCAL_CONFIG_FILE = \
"""
{
	"section_name": "HOME"
}
""".strip()

CONTENT_IN_DIARY_LOCAL_CONFIG_FILE = \
"""
{
	"section_name": "DIARY"
}
""".strip()

CONTENT_STINGINGNETTLEPY_CONFIG_FILE = \
"""
{
	"website_name": "",
	"test":
	{
		"absolute_path": "",
		"website_root_dir": ""	
	},
	"upload": {
		"username": "",
		"password": "",
		"absolute_path": "",
		"website_root_dir": "",
		"host": "",
		"port": ""
	}
}
""".strip()

CONTENT_NAVIGATION_FILE = \
"""
{
	"home": [
		"index.html", "Index",
		"news.html", "News"
	],
	"about": [
		"index.html", "Index"
	],
	"diary": [
		"index.html", "Index",
		"november_2013.html", "November 2013",		
		"december_2013.html", "December 2013"
	]
}
""".strip()

CONTENT_IN_HOME_INDEX_FILE = \
"""
{
	"page_name": "INDEX"
}
---config---
|||main_content
<p>Welcome to this example website!</p>
|||main_content
""".strip()

CONTENT_IN_HOME_NEWS_FILE = \
"""
{
	"page_name": "NEWS"
}
---config---
|||main_content
<p>These are the news!</p>
|||main_content
""".strip()

CONTENT_IN_ABOUT_INDEX_FILE = \
"""
{
	"template": "advanced.template",
	"section_name": "ABOUT",
	"page_name": "INDEX",
	"func_silly_things": {
		"module_name": "testmodule",
		"function_name": "rand_number",
		"parameters": [ 1, 50 ],
		"container_name": "random_number"
	}
}
---config---
|||main_content
<p>Some information about me.</p>
|||main_content
|||container_two
<p>$random_number.</p>
|||container_two
""".strip()

CONTENT_IN_DIARY_INDEX_FILE = \
"""
{
	"page_name": "INDEX"
}
---config---
|||main_content
<p>Welcome to the $section_name section.</p>
|||main_content
""".strip()

CONTENT_IN_DIARY_NOVEMBER_2013_FILE = \
"""
{
	"page_name": "NEWS"
}
---config---
|||main_content
<p>Nothing here.</p>
|||main_content
""".strip()

CONTENT_IN_DIARY_DECEMBER_2013_FILE = \
"""
{
	"page_name": "INDEX"
}
---config---
|||main_content
<p>Nothing here.</p>
|||main_content
""".strip()

CONTENT_MODULE_TEST_MODULE_FILE = \
"""
import random

def rand_number( low, high ):
	return "Your random number is '%s'" % ( random.randint( low, high ) )
""".strip()

# Definition of constants.
# Global preferences/settings
ROOT_DIR = os.getcwd()

WEBSITE_DIRECTORY = os.path.basename( os.getcwd() )
TEMPLATES_DIRECTORY = "templates"
MODULES_DIRECTORY = "modules"
WEBSITE_INPUT_DIRECTORY = "in"
WEBSITE_OUTPUT_DIRECTORY = "out"
WEBSITE_LOGS_DIRECTORY = "logs"
GLOBAL_CONFIG_FILE = "global.config"
LOCAL_CONFIG_FILE = "local.config"
NAVIGATION_FILE = "navigation.json"
LOG_FILE_SUFFIX = "log.txt"
STINGINGNETTLEPY_CONFIG_FILE = "stingingnettlepy.config"
WEBSITE_BACKUPS_DIRECTORY = "backups"
WEBSITE_OUTPUT_DIRECTORY_LAST_VERSION = "last_version"

# This file makes sure that a directory on a web-server has indeed been created by 'Stingingnettlepy'.
GENERATED_WITH_STINGINGNETTLEPY_PROTECTION_FILE = "generated_with_stingingnettlepy.txt"

# 'Stingingnettlepy project website directory' data (LPWD data)
STINGINGNETTLEPY_PROJECT_WEBSITE_DIRECTORY_DATA = {
	"directories": (
		os.path.join( WEBSITE_INPUT_DIRECTORY ),
		os.path.join( WEBSITE_OUTPUT_DIRECTORY ),
		os.path.join( MODULES_DIRECTORY ),
		os.path.join( TEMPLATES_DIRECTORY ),
		os.path.join( WEBSITE_LOGS_DIRECTORY ),
		os.path.join( WEBSITE_BACKUPS_DIRECTORY ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_css" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_js" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_media" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_media", "photos" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_media", "videos" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_media", "music" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "_media", "downloads" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "home" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "about" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, "diary" )
	),
	"files": (
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "_css", "basic.css" ),
		 	"content": CONTENT_CSS_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "_js", "basic.js" ),
		 	"content": CONTENT_JS_FILE
		},		
		{
			"path": os.path.join( TEMPLATES_DIRECTORY, "basic.template" ),
		 	"content": CONTENT_BASIC_TEMPLATE
		},
		{
			"path": os.path.join( TEMPLATES_DIRECTORY, "advanced.template" ),
		 	"content": CONTENT_ADVANCED_TEMPLATE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "home", "local.config" ),
		 	"content": CONTENT_IN_HOME_LOCAL_CONFIG_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "diary", "local.config" ),
		 	"content": CONTENT_IN_HOME_LOCAL_CONFIG_FILE
		},				
		{
			"path": os.path.join( MODULES_DIRECTORY, "__init__.py" ),
		 	"content": ""
		},
		{
			"path": os.path.join( MODULES_DIRECTORY, "testmodule.py" ),
		 	"content": CONTENT_MODULE_TEST_MODULE_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, GLOBAL_CONFIG_FILE ),
		 	"content": CONTENT_GLOBAL_CONFIG_FILE
		},		
		{
			"path": os.path.join( STINGINGNETTLEPY_CONFIG_FILE ),
		 	"content": CONTENT_STINGINGNETTLEPY_CONFIG_FILE
		},
		{
			"path": os.path.join( NAVIGATION_FILE ),
		 	"content": CONTENT_NAVIGATION_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "home", "index.txt" ),
		 	"content": CONTENT_IN_HOME_INDEX_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "home", "news.txt" ),
		 	"content": CONTENT_IN_HOME_NEWS_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "about", "index.txt" ),
		 	"content": CONTENT_IN_ABOUT_INDEX_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "diary", "index.txt" ),
		 	"content": CONTENT_IN_DIARY_INDEX_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "diary", "november_2013.txt" ),
		 	"content": CONTENT_IN_DIARY_NOVEMBER_2013_FILE
		},
		{
			"path": os.path.join( WEBSITE_INPUT_DIRECTORY, "diary", "december_2013.txt" ),
		 	"content": CONTENT_IN_DIARY_DECEMBER_2013_FILE
		},
	)
}

# 'Stingingnettlepy' required directories and files.
STINGINGNETTLEPY_PROJECT_WEBSITE_DIRECTORY_REQUIRED_DIRS_AND_FILES = {
	"directories": (
		os.path.join( WEBSITE_INPUT_DIRECTORY ),
		os.path.join( MODULES_DIRECTORY ),
		os.path.join( TEMPLATES_DIRECTORY ),
		os.path.join( WEBSITE_BACKUPS_DIRECTORY )
	),
	"files": (
		os.path.join( TEMPLATES_DIRECTORY, "basic.template" ),
		os.path.join( MODULES_DIRECTORY, "__init__.py" ),
		os.path.join( WEBSITE_INPUT_DIRECTORY, GLOBAL_CONFIG_FILE )
	)
}
